package com.whizen.commons.date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

/**
 * 日期工具类
 * 
 * @author 杨浩泉
 * @date 2016年4月4日
 */
public class DateKit {

	/**
	 * 日期格式 yyyy-MM-dd
	 */
	public static final String DATE = "yyyy-MM-dd";
	/**
	 * 日期格式 HH:mm:ss
	 */
	public static final String TIME = "HH:mm:ss";
	/**
	 * 日期格式 yyyy-MM-dd HH:mm:ss
	 */
	public static final String DATETIME = "yyyy-MM-dd HH:mm:ss";

	/**
	 * 获取当前年份
	 * 
	 * @return
	 */
	public static final int getYear() {
		return getCalendar().get(Calendar.YEAR);
	}

	/**
	 * 获取指定日期年份
	 * 
	 * @param date
	 *            日期
	 * @return
	 */
	public static final int getYear(Date date) {
		return getCalendar(date).get(Calendar.YEAR);
	}

	/**
	 * 获取当前月份
	 * 
	 * @return
	 */
	public static final int getMonth() {
		return getCalendar().get(Calendar.MONTH) + 1;
	}

	/**
	 * 获取指定日期月份
	 * 
	 * @param date
	 *            日期
	 * @return
	 */
	public static final int getMonth(Date date) {
		return getCalendar(date).get(Calendar.MONTH) + 1;
	}

	/**
	 * 获取当前日
	 * 
	 * @return
	 */
	public static final int getDay() {
		return getCalendar().get(Calendar.DATE);
	}

	/**
	 * 获取指定日期月份
	 * 
	 * @param date
	 *            日期
	 * @return
	 */
	public static final int getDay(Date date) {
		return getCalendar(date).get(Calendar.DATE);
	}

	/**
	 * 获取今天是这个月第几天，即几号了
	 * 
	 * @return
	 */
	public static final int getDayInMonth() {
		return getCalendar().get(Calendar.DAY_OF_MONTH);
	}

	/**
	 * 获取指定日期这个月第几天，即几号了
	 * 
	 * @param date
	 *            日期
	 * @return
	 */
	public static final int getDayInMonth(Date date) {
		return getCalendar(date).get(Calendar.DAY_OF_MONTH);
	}

	/**
	 * 获取今天是星期几
	 * 
	 * @return
	 */
	public static final int getWeek() {
		return getCalendar().get(Calendar.DAY_OF_WEEK) - 1;
	}

	/**
	 * 获取指定日期是星期几
	 * 
	 * @param date
	 *            日期
	 * @return
	 */
	public static final int getWeek(Date date) {
		return getCalendar(date).get(Calendar.DAY_OF_WEEK) - 1;
	}

	/**
	 * 获取这个月是第几周
	 * 
	 * @return
	 */
	public static final int getDayOfWeekInMonth() {
		return getCalendar().get(Calendar.DAY_OF_WEEK_IN_MONTH);
	}

	/**
	 * 获取指定日期是第几周
	 * 
	 * @param date
	 *            日期
	 * @return
	 */
	public static final int getDayOfWeekInMonth(Date date) {
		return getCalendar(date).get(Calendar.DAY_OF_WEEK_IN_MONTH);
	}

	/**
	 * 获取今天是今年第几天
	 * 
	 * @return
	 */
	public static final int getDayInYear() {
		return getCalendar().get(Calendar.DAY_OF_YEAR);
	}

	/**
	 * 获取指定日期是第几天
	 * 
	 * @param date
	 * @return
	 */
	public static final int getDayInYear(Date date) {
		return getCalendar(date).get(Calendar.DAY_OF_YEAR);
	}

	/**
	 * 当前日期
	 * 
	 * @return 字符串日期
	 */
	public static final String now() {
		return convertDate2String(new Date(), DATETIME);
	}

	/**
	 * 格式化日期：yyyy-MM-dd
	 * 
	 * @param date
	 * @return 返回字符串日期
	 */
	public static final String formatDate(Date date) {
		return convertDate2String(date, DATE);
	}

	/**
	 * 格式化日期：yyyy-MM-dd HH:mm:ss
	 * 
	 * @param date
	 * @return 返回字符串日期
	 */
	public static final String formatDatetime(Date date) {
		return convertDate2String(date, DATETIME);
	}

	/**
	 * 格式化日期：yyyy-MM-dd
	 * 
	 * @param date
	 *            字符串日期
	 * @return 返回日期对象
	 */
	public static final Date formatDate(String date) {
		return convertString2Date(date, DATE);
	}

	/**
	 * 格式化日期：yyyy-MM-dd HH:mm:ss
	 * 
	 * @param date
	 *            字符串日期
	 * @return 返回日期对象
	 */
	public static final Date formatDateTime(String date) {
		return convertString2Date(date, DATETIME);
	}

	/**
	 * 日期转字符串
	 * 
	 * @param date
	 *            待转换的日期
	 * @param format
	 *            日期格式
	 * @return
	 */
	public static final String convertDate2String(Date date, String format) {
		SimpleDateFormat df = null;
		String returnValue = "";
		if (date != null) {
			df = new SimpleDateFormat(format);
			returnValue = df.format(date);
		}

		return returnValue;
	}

	/**
	 * 字符串日期转Date类型
	 * 
	 * @param strDate
	 *            待转换的字符串日期
	 * @param format
	 *            格式
	 * @return
	 */
	public static final Date convertString2Date(String strDate, String format) {
		SimpleDateFormat df = null;
		Date date = null;

		if (strDate != null) {
			df = new SimpleDateFormat(format);
			try {
				date = df.parse(strDate);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}

		return date;
	}

	/**
	 * 字符串日期转Date类型
	 * 
	 * @param strDate
	 *            待转换的字符串日期
	 * @return
	 */
	public static final Date convertString2Date(String strDate) {
		return convertString2Date(strDate, DATETIME);
	}

	/**
	 * 获取Calendar对象
	 * 
	 * @return
	 */
	public static Calendar getCalendar() {
		return Calendar.getInstance();
	}

	/**
	 * 指定日期获取Calendar对象
	 * 
	 * @param year
	 *            年
	 * @param month
	 *            月
	 * @param day_of_month
	 *            日
	 * @return 返回Calendar对象
	 */
	public static Calendar getCalendar(int year, int month, int day_of_month) {
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month - 1);
		cal.set(Calendar.DAY_OF_MONTH, day_of_month);
		return cal;
	}

	/**
	 * 根据指定日期获取Calendar对象
	 * 
	 * @param date
	 *            日期对象
	 * @return Calendar
	 */
	public static Calendar getCalendar(Date date) {
		Calendar c = getCalendar();
		c.setTime(date);
		return c;
	}

	/**
	 * 指定年月日获取Date对象
	 * 
	 * @param year
	 *            年
	 * @param month
	 *            月
	 * @param day
	 *            日
	 * @return 返回Date对象
	 */
	public static Date getDate(int year, int month, int day) {
		Calendar c = getCalendar();
		c.set(Calendar.YEAR, year);
		c.set(Calendar.MONTH, month);
		c.set(Calendar.DATE, day);
		return c.getTime();
	}

	/**
	 * 用字符串获得日期
	 * 
	 * @throws ParseException
	 * @dateValue 日期字符串
	 * @dateType 格式化的类型,date和datetime
	 */
	public static Date getDate(String dateValue, String dateType) throws ParseException {
		if (dateValue == null)
			return null;
		if (dateType.equals(TIME)) {
			SimpleDateFormat sfdate = new SimpleDateFormat(TIME);
			return sfdate.parse(dateValue);
		} else if (dateType.equals(DATE)) {
			SimpleDateFormat sftime = new SimpleDateFormat(DATE);
			return sftime.parse(dateValue);
		} else if (dateType.equals(DATETIME)) {
			SimpleDateFormat sftime = new SimpleDateFormat(DATETIME);
			return sftime.parse(dateValue);
		}
		return null;
	}

	/**
	 * 获取日期相差值
	 * 
	 * <pre>
	 * 例子： 
	 *     DateKit.diff(formatDate("2016-03-01"), formatDate("2016-03-15"), Calendar.WEEK_OF_YEAR); 
	 *     输入出结果：2
	 *     相差两个星期
	 *     
	 *     DateKit.diff(formatDate("2016-03-01"), formatDate("2016-03-15"), Calendar.DATE);
	 *     输入出结果：14
	 *     相差14天
	 * </pre>
	 * 
	 * @param startDate
	 *            开始日期
	 * @param endDate
	 *            结束日期
	 * @param field
	 *            Calendar字段：YEAR、MONTH、WEEK_OF_YEAR(星期)、DATE、HOUR、MINUTE、SECOND、MILLISECOND
	 * @return
	 */
	public static long diff(Date startDate, Date endDate, int field) {
		long ms = endDate.getTime() - startDate.getTime();
		// 如果d2在d1前面
		if (getCalendar(endDate).before(getCalendar(startDate))) {
			Date d0 = endDate;// 记录后一个日期
			endDate = startDate;
			startDate = d0;
			d0 = null;
		}
		;
		long res = 0;
		switch (field) {
		case Calendar.YEAR:
			Calendar c = getCalendar(endDate);
			c.set(Calendar.YEAR, getYear(startDate));// 将年设置成相同的
			// 然后比较日期前后关系，如果d0在d1前面，年份-1
			res = getYear(endDate) - getYear(startDate) - (c.before(getCalendar(startDate)) ? 1 : 0);
			break;

		case Calendar.MONTH:
			int years = getYear(endDate) - getYear(startDate);
			Calendar c1 = getCalendar(endDate);
			c1.set(Calendar.YEAR, getYear(startDate));// 将年设置成相同的
			c1.set(Calendar.MONTH, getMonth(startDate) - 1);// 将年设置成相同的
			// 然后比较日期前后关系，如果d0在d1前面，月份-1
			res = (getMonth(endDate) >= getMonth(startDate) ? (getMonth(endDate) - getMonth(startDate)) : (--years * 0) + (getMonth(endDate) + 12 - getMonth(startDate)) % 12) + years * 12 - (c1.before(getCalendar(startDate)) ? 1 : 0);
			break;

		case Calendar.WEEK_OF_YEAR:
			res = ms / (7 * 24 * 60 * 60 * 1000);
			break;

		case Calendar.DATE:
			res = ms / (24 * 60 * 60 * 1000);
			break;

		case Calendar.HOUR:
			res = ms / (60 * 60 * 1000);
			break;

		case Calendar.MINUTE:
			res = ms / (60 * 1000);
			break;

		case Calendar.SECOND:
			res = ms / (1000);
			break;

		case Calendar.MILLISECOND:
			res = ms;
			break;

		default:
			break;
		}
		return res;
	}

	/**
	 * 获取指定年份的1~12月的每月的开始和结束
	 * 
	 * @param year
	 *            年份 2016
	 * @return 返回Map集合
	 */
	public static Map<Integer, String[]> getMonthDateMap(Integer year) {
		return start_end_months(year);
	}

	/**
	 * 获取当前年的1~12月的每月的开始和结束
	 * 
	 * @return 返回Map集合
	 */
	public static Map<Integer, String[]> getMonthDateMap() {
		return start_end_months(getYear());
	}

	/**
	 * 获取指定月的开始和结束
	 * 
	 * @param year
	 *            年份
	 * @param month
	 *            月份
	 * @return 返回数组
	 */
	public static String[] getMonthDates(Integer year, Integer month) {
		return start_end_months(year) != null ? start_end_months(year).get(month) : null;
	}

	/**
	 * 获取指定月(当前年)的开始和结束
	 * 
	 * @param month
	 *            月份
	 * @return 返回数组
	 */
	public static String[] getMonthDates(Integer month) {
		return start_end_months(getYear()) != null ? start_end_months(getYear()).get(month) : null;
	}

	/**
	 * 计算指定年份的1~12月的开始和结束
	 * 
	 * @param year
	 * @return 返回数组
	 */
	private static Map<Integer, String[]> start_end_months(Integer year) {
		if (null != year) {
			Map<Integer, String[]> monthDateMap = new LinkedHashMap<Integer, String[]>();

			Calendar date = Calendar.getInstance();
			date.set(Calendar.YEAR, year);
			for (int i = 0; i < 12; i++) {

				date.set(Calendar.MONTH, i);
				int minMonthDate = date.getActualMinimum(Calendar.DAY_OF_MONTH);
				date.set(Calendar.DATE, minMonthDate);
				String startMonth = formatDate(date.getTime());
				int maxMonthDate = date.getActualMaximum(Calendar.DAY_OF_MONTH);
				date.set(Calendar.DATE, maxMonthDate);
				String endMonth = formatDate(date.getTime());

				String monthDate[] = { startMonth, endMonth };
				monthDateMap.put(i + 1, monthDate);
			}
			return monthDateMap;
		}
		return null;
	}

	/**
	 * 计算两个日期的相差天数
	 * 
	 * @param d1
	 *            开始日期
	 * @param d2
	 *            结束日期
	 * @return 返回相差天数
	 */
	public static int getDaysBetween(Calendar d1, Calendar d2) {
		if (d1.after(d2)) { // 交换日期
			Calendar swap = d1;
			d1 = d2;
			d2 = swap;
		}
		int days = d2.get(Calendar.DAY_OF_YEAR) - d1.get(Calendar.DAY_OF_YEAR);
		int y2 = d2.get(Calendar.YEAR);
		if (d1.get(Calendar.YEAR) != y2) {
			d1 = (Calendar) d1.clone();
			do {
				days += d1.getActualMaximum(Calendar.DAY_OF_YEAR);
				d1.add(Calendar.YEAR, 1);
			} while (d1.get(Calendar.YEAR) != y2);
		}
		return days;
	}

	/**
	 * 获得日期的下一个星期一的日期<br>
	 * 
	 * <pre>
	 * 	 调用：DateKit.formatDate(getNextMonday(getCalendar(2016, 4, 6)).getTime());
	 * </pre>
	 * 
	 * @param date
	 * @return
	 */
	public static Calendar getNextMonday(Calendar date) {
		Calendar result = null;
		result = date;
		do {
			result = (Calendar) result.clone();
			result.add(Calendar.DATE, 1);
		} while (result.get(Calendar.DAY_OF_WEEK) != 2);
		return result;
	}

	/**
	 * 计算2个日期之间的相隔天数 工作日
	 * 
	 * @param d1
	 * @param d2
	 * @return
	 */
	/**
	 * 计算两个日期之间的相差天数（包含今天），仅计算有效工作日，排除周六日
	 * 
	 * @param Calendar
	 *            start 开始日期
	 * @param Calendar
	 *            end 结束日期
	 * @return 返回两个日期之间的有效工作日
	 */
	public static int getWorkingDay(Calendar start, Calendar end) {
		int result = -1;
		if (start.after(end)) { // 交换日期，D1和D2是结束的开始
			Calendar swap = start;
			start = end;
			end = swap;
		}

		int charge_start_date = 0;// 开始日期的日期偏移量
		int charge_end_date = 0;// 结束日期的日期偏移量
		// 日期不在同一个日期内
		int stmp;
		int etmp;
		stmp = 7 - start.get(Calendar.DAY_OF_WEEK);
		etmp = 7 - end.get(Calendar.DAY_OF_WEEK);
		if (stmp != 0 && stmp != 6) {// 开始日期为星期六和星期日时偏移量为0
			// 不包含今天
			// charge_start_date = stmp - 1;
			// 包含今天
			charge_start_date = stmp;
		}
		if (etmp != 0 && etmp != 6) {// 结束日期为星期六和星期日时偏移量为0
			charge_end_date = etmp - 1;
		}
		result = (getDaysBetween(getNextMonday(start), getNextMonday(end)) / 7) * 5 + charge_start_date - charge_end_date;
		return result;
	}

	/**
	 * 计算两个日期之间的相差天数（包含今天），仅计算有效工作日，排除周六日
	 * 
	 * @param Date
	 *            start 开始日期
	 * @param Date
	 *            end 结束日期
	 * @return 返回两个日期之间的有效工作日
	 */
	public static int getWorkingDay(Date start, Date end) {
		Calendar cal_start = Calendar.getInstance();
		Calendar cal_end = Calendar.getInstance();
		cal_start.setTime(start);
		cal_end.setTime(end);
		return getWorkingDay(cal_start, cal_end);
	}

	/**
	 * 计算两个日期之间的相差天数（包含今天），仅计算有效工作日，排除周六日
	 * 
	 * @param String
	 *            start 开始日期
	 * @param String
	 *            end 结束日期
	 * @return 返回两个日期之间的有效工作日
	 */
	public static int getWorkingDay(String start, String end) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Date date_start = sdf.parse(start);
			Date date_end = sdf.parse(end);

			Calendar cal_start = Calendar.getInstance();
			Calendar cal_end = Calendar.getInstance();
			cal_start.setTime(date_start);
			cal_end.setTime(date_end);
			return getWorkingDay(cal_start, cal_end);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return 0;
	}

	/**
	 * 获取指定月份工作天数（排除周六日）
	 * 
	 * @param month
	 * @return
	 */
	public static int getWorkingDayMonth(int month) {
		try {
			Calendar fristDay = Calendar.getInstance();
			fristDay.setTime(new SimpleDateFormat("yyyy").parse(new SimpleDateFormat("yyyy").format(new Date())));
			fristDay.add(Calendar.MONTH, month - 1);
			fristDay.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天

			Calendar lastDay = Calendar.getInstance();
			lastDay.setTime(new SimpleDateFormat("yyyy").parse(new SimpleDateFormat("yyyy").format(new Date())));
			lastDay.add(Calendar.MONTH, month - 1);
			lastDay.set(Calendar.DAY_OF_MONTH, lastDay.getActualMaximum(Calendar.DAY_OF_MONTH));

			int workDay = getWorkingDay(fristDay, lastDay);

			return workDay;
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return 0;
	}

	/**
	 * 获取当前年的工作天数，排除周六日
	 * 
	 * @return
	 */
	public static int getCurrentYearWorkingDay() {
		int allWrokDay = 0;
		try {
			for (int month = 1; month <= 12; month++) {
				Calendar fristDay = Calendar.getInstance();
				fristDay.setTime(new SimpleDateFormat("yyyy").parse(new SimpleDateFormat("yyyy").format(new Date())));
				fristDay.add(Calendar.MONTH, month - 1);
				fristDay.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天

				Calendar lastDay = Calendar.getInstance();
				lastDay.setTime(new SimpleDateFormat("yyyy").parse(new SimpleDateFormat("yyyy").format(new Date())));
				lastDay.add(Calendar.MONTH, month - 1);
				lastDay.set(Calendar.DAY_OF_MONTH, lastDay.getActualMaximum(Calendar.DAY_OF_MONTH));

				int diff = getWorkingDay(fristDay, lastDay);
				allWrokDay += diff;
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return allWrokDay;
	}

	/**
	 * 获取中文星期几
	 * 
	 * @param Date
	 *            date
	 * @return 日期字符串
	 */
	public static String getWeekOfDate(Date date) {
		String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
		if (w < 0)
			w = 0;
		return weekDays[w];
	}

	/**
	 * 计算指定的时间与当前时间的间隔<br>
	 * 
	 * <pre>
	 * DateKit.getDaysBeforeNow(formatDate(&quot;2016-04-08&quot;));
	 * DateKit.getDaysBeforeNow(formatDateTime(&quot;2016-04-08 18:20:30&quot;));
	 * </pre>
	 * 
	 * @param Date
	 *            date
	 * @return 返回（？年前、？月前、？天前、？小时前、？分钟前）
	 */
	public static String getDaysBeforeNow(Date date) {
		long sysTime = Long.parseLong(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
		long ymdhms = Long.parseLong(new SimpleDateFormat("yyyyMMddHHmmss").format(date));
		String strYear = "年前";
		String strMonth = "月前";
		String strDay = "天前";
		String strHour = "小时前";
		String strMinute = "分钟前";
		try {
			if (ymdhms == 0) {
				return "";
			}
			long between = (sysTime / 10000000000L) - (ymdhms / 10000000000L);
			if (between > 0) {
				return between + strYear;
			}
			between = (sysTime / 100000000L) - (ymdhms / 100000000L);
			if (between > 0) {
				return between + strMonth;
			}
			between = (sysTime / 1000000L) - (ymdhms / 1000000L);
			if (between > 0) {
				return between + strDay;
			}
			between = (sysTime / 10000) - (ymdhms / 10000);
			if (between > 0) {
				return between + strHour;
			}
			between = (sysTime / 100) - (ymdhms / 100);
			if (between > 0) {
				return between + strMinute;
			}
			return "1" + strMinute;
		} catch (Exception e) {
			return "";
		}
	}

	/**
	 * 判定日期是否在指定范围
	 * 
	 * @param datetime
	 * @param startDatetime
	 * @param endDatetime
	 * @return
	 */
	public static boolean datetimeScope(String datetime, String startDatetime, String endDatetime, String dateType) {
		try {
			Calendar curtime = Calendar.getInstance();
			curtime.setTime(getDate(datetime, dateType));

			Calendar sTime = Calendar.getInstance();
			sTime.setTime(getDate(startDatetime, dateType));

			Calendar eTime = Calendar.getInstance();
			eTime.setTime(getDate(endDatetime, dateType));

			if (curtime.getTimeInMillis() >= sTime.getTimeInMillis() && curtime.getTimeInMillis() <= eTime.getTimeInMillis()) {
				return true;
			} else {
				return false;
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return false;
	}

	/******************************************** end ***********************************************************/

	public static void main(String[] args) {

		System.out.println("年份：" + getYear());
		System.out.println("月份：" + getMonth());
		System.out.println("日期：" + getDay());
		System.out.println("几号：" + getDayInMonth());
		System.out.println("星期几：" + getWeek());
		System.out.println("这个月第几周：" + getDayOfWeekInMonth());
		System.out.println("今年第几天： " + getDayInYear());
		System.out.println("属相年：" + LunarKit.animalsYear(getYear()));
		System.out.println("农历：" + LunarKit.getLunar(convertString2Date("2009-06-27", "yyyy-MM-dd")));
		System.out.println("农历：" + LunarKit.getLunar(convertString2Date("2009-06-27", "yyyy-MM-dd"), true));
		System.out.println("农历：" + LunarKit.getLunar(convertString2Date(now(), "yyyy-MM-dd"), true));
		System.out.println("两个日期相差多少个年：" + diff(formatDate("2005-11-01"), formatDate("2015-11-01"), Calendar.YEAR));
		System.out.println("两个日期相差多少个月：" + diff(formatDateTime("2005-11-01 10:00:00"), formatDateTime("2015-11-01 10:00:00"), Calendar.MONTH));

		System.out.println();

		String[] monthDates = getMonthDates(2016, 3);
		System.out.println("第 " + 3 + " 个月的开始日期为：" + monthDates[0] + "，结束日期为：" + monthDates[1]);
		System.out.println();

		Map<Integer, String[]> monthDate = getMonthDateMap(2016);
		Set<Entry<Integer, String[]>> set = monthDate.entrySet();
		for (Entry<Integer, String[]> entry : set) {
			Integer monthNum = entry.getKey();
			String[] months = entry.getValue();
			System.out.println("第 " + monthNum + " 个月的开始日期为：" + months[0] + "，结束日期为：" + months[1]);
		}

		System.out.println();
		System.out.println("以下是计算两个日期相差天数，仅有效工作日（排除周六日）");
		System.out.println("包含今天[2016-04-01 2016-04-04]：" + getWorkingDay("2016-04-30", "2016-04-01"));
		;
		System.out.println("包含今天[2016-04-01 2016-04-30]：" + getWorkingDay("2016-04-01", "2016-04-30"));
		;
		System.out.println("获取当前年指定月份的有效工作天数：" + getWorkingDayMonth(4));
		System.out.println("获取当前年的有效工作天数：" + getCurrentYearWorkingDay());

		System.out.println();

		Calendar d1 = getCalendar(2016, 4, 1);
		Calendar d2 = getCalendar(2016, 4, 9);

		System.out.println("计算连个日期的相差天数【2016-04-01 2016-04-02】：" + getDaysBetween(d1, d2));
		;

		System.out.println("获取日期的下一个星期一【2014-04-06】：" + formatDate(getNextMonday(getCalendar(2016, 4, 6)).getTime()));

		System.out.println("获取星期几【2016-04-03】：" + getWeekOfDate(formatDate("2016-04-03")));

		System.out.println("计算指定的时间与当前时间的间隔【2016-04-08 18:20:30】：" + getDaysBeforeNow(formatDateTime("2016-04-08 18:20:30")));

		System.out.println(datetimeScope("2016-04-05", "2016-04-05", "2016-04-05", DATE));
		System.out.println(datetimeScope("2016-04-06", "2016-04-01", "2016-04-05", DATE));
		System.out.println(datetimeScope("2016-04-05 12:30:31", "2016-04-01 12:01:01", "2016-04-05 12:30:30", DATETIME));

	}

}
